package logic

import (
	"context"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartSearchLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartSearchLogic {
	return &CartSearchLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartSearchLogic) CartSearch(in *homepage.CartSearchRequest) (*homepage.CartSearchResponse, error) {
	// todo: add your logic here and delete this line
	search, err := dao.CartSearch(int(in.UserId), in.Name)
	if err != nil {
		pkg.Error("搜索失败", zap.Error(err))
		return nil, err
	}
	return &homepage.CartSearchResponse{List: search}, nil
}
